package com.bea.ftd.dashboard.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.expression.Lists;

import com.bea.ftd.common.ValidationException;
import com.bea.ftd.common.entity.SecretInfo;
import com.bea.ftd.common.enums.EncryptEnum;
import com.bea.ftd.dashboard.domain.AjaxResponse;
import com.bea.ftd.dashboard.enums.ResponseStatus;
import com.bea.ftd.dashboard.service.ISecretInfoService;

@RestController
@RequestMapping("/secretInfo")
public class SecretInfoController {
	private Logger LOGGER = LoggerFactory.getLogger(SecretInfoController.class);

	@Autowired
	private ISecretInfoService secretInfoServiceImpl;

	@RequestMapping("/listAll")
	public List<SecretInfo> listAllSecretInfos() {
		return secretInfoServiceImpl.getAllSecretInfos();
	}

	@RequestMapping("/saveOrUpdate")
	public AjaxResponse addSecretInfo(SecretInfo secretInfo) {
		LOGGER.info("Save or update secretInfo - " + secretInfo.toString());
		try {
			secretInfoServiceImpl.addSecretInfo(secretInfo);
			return new AjaxResponse(ResponseStatus.SUCCESS);
		} catch (ValidationException e) {
			LOGGER.error("输入参数错误：" + e.getErrorMessage());
			return new AjaxResponse(ResponseStatus.FAIL, e.getErrorMessage());
		} catch (Exception e) {
			LOGGER.error("Error in saving secretInfo to DB. " + e.getMessage());
			return new AjaxResponse(ResponseStatus.FAIL, e.getMessage());
		}

	}

}
